package com.djakapm.markdown.editor.util;

import org.apache.commons.configuration.ConfigurationException;
import org.junit.*;
import junit.framework.JUnit4TestAdapter;

import static junit.framework.Assert.assertTrue;

public class SpecForConfigManager {
    public static junit.framework.Test suite() {
        return new JUnit4TestAdapter(SpecForConfigManager.class);
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    @Test
    public void load_properties_file() {
        try {
            ConfigManager.init("src/main/resources/marked.properties");
        } catch (ConfigurationException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    @Test
    public void can_read_property(){
        try {
            ConfigManager.init("src/main/resources/marked.properties");
        } catch (ConfigurationException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

        assertTrue("Marked - Markdown Editor v.0.1".equals(ConfigManager.get("app.name")));
    }

    @Test
    public void handle_non_existed_property(){
        try {
            ConfigManager.init("src/main/resources/marked.properties");
        } catch (ConfigurationException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        assertTrue("".equals(ConfigManager.get("non.existed.key")));
    }

    @Test
    public void handle_empty_string_key(){
        try {
            ConfigManager.init("src/main/resources/marked.properties");
        } catch (ConfigurationException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        assertTrue("".equals(ConfigManager.get("")));
    }


    @Test
    public void handle_null_key(){
        try {
            ConfigManager.init("src/main/resources/marked.properties");
        } catch (ConfigurationException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        assertTrue("".equals(ConfigManager.get(null)));
    }

}